package com.itheima.个人代码.编码和解码;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Demo1 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String s = "中国黑马程序员asds";
        getBytes默认(s);
        getBytesGBK(s, "GBK");
        //utf-8编码
        getBytesGBK(s, "utf-8");


    }

    public static void getBytesGBK(String s, String gbk) throws UnsupportedEncodingException {
        //GBK编码
        byte[] bytes1 = s.getBytes(gbk);
        System.out.println(Arrays.toString(bytes1));
        //GBK解码
        String string2 = new String(bytes1, gbk);
        System.out.println(string2);
        System.out.println("........................");
    }

    public static void getBytes默认(String s) {
        //默认平台编码
        byte[] bytes = s.getBytes();
        System.out.println(Arrays.toString(bytes));
        //默认平台解码
        String string1 = new String(bytes);
        System.out.println(string1);
        System.out.println("........................");
    }
}
